<template>
  <div class="home">
    <el-card v-if="showTable">
      <el-radio-group v-model="adioGroup"  @change="changeAdioGroup">
        <el-radio-button label="1">安防</el-radio-button>
        <el-radio-button label="2">库房</el-radio-button>
        <el-radio-button label="3">运维</el-radio-button>
      </el-radio-group>
      <!--安防-->
      <el-table v-if="adioGroup === '1'"  :data="tableData" border v-loading="showLoading">
        <el-table-column label="巡检人" prop="formData.textField_ku7s0n2n"></el-table-column>
        <el-table-column label="巡检分类" prop="formData.selectField_ku57fv1f"></el-table-column>
        <el-table-column label="巡检地点" prop="formData.checkboxField_ku7s0n2sArr" :show-overflow-tooltip="true" />
        <el-table-column label="巡检结果" prop="formData.textareaField_ku57fv1i" :show-overflow-tooltip="true"></el-table-column>
      </el-table>
      <!--库房-->
      <div v-if="adioGroup === '2'">
        <el-radio-group class="school-type" style="margin-top: 20px" v-model="schoolType"  @change="changeSchoolType">
          <el-radio-button label="1">小学</el-radio-button>
          <el-radio-button label="2">幼儿园</el-radio-button>
        </el-radio-group>
        <el-table   :data="tableData" border v-loading="showLoading">
          <el-table-column label="类型" prop="formData.textField_kt56hbgs"></el-table-column>
          <el-table-column v-if="schoolType === '1'" label="小计" prop="formData.textField_kti1ywuw"></el-table-column>
          <el-table-column v-if="schoolType === '2'" label="小计" prop="formData.numberField_kt56hbgt"></el-table-column>
        </el-table>
      </div>
      <!--运维-->
      <el-table v-if="adioGroup === '3'"  :data="tableData" border v-loading="showLoading">
        <el-table-column label="报修人" prop="formData.employeeField_ku28djp1[0]"></el-table-column>
        <el-table-column label="报修主题" prop="formData.radioField_ku2bj4ud" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="地点" prop="formData.selectField_ku29ybtb" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="描述" prop="formData.textField_ku3fn1v6" :show-overflow-tooltip="true"></el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
  import elTree from '@/components/el-tree'
  import ElTabPane from "element-ui/packages/tabs/src/tab-pane";
  import { DdXyYyAfDaData,DdXyYyStDaData,DdXyYyYeyDaData, DdXyYyYiDaData } from '@/api/home.js'
  import { userInfo } from '@/api/user'
  let _this = null
  export default {
    name: 'homeIndex',
    data() {
      return {
        showTable: false,
        adioGroup: '1', // 默认安防
        schoolType: '1',// 学校类型
        showLoading:false,
        tableData: []
      }
    },
    created() {
      _this = this
      _this.getUserInfo()
    },
    methods: {
      changeAdioGroup(e){
        _this.showLoading = true
        _this.schoolType = '1'
        if(_this.adioGroup === '1'){ //安防
          _this.DdXyYyAfDaData()
        }else if(_this.adioGroup === '2'){ // 库房
          _this.DdXyYyStDaData()
        }else if(_this.adioGroup === '3'){ // 运维
          _this.DdXyYyYiDaData()
        }else{
          return
        }
      },
      changeSchoolType(e){
        _this.showLoading = true
        if(_this.schoolType === '1'){ // 小学
          _this.DdXyYyStDaData()
        }else if(_this.schoolType === '2'){ // 幼儿园
          _this.DdXyYyYeyDaData()
        }else{
          return
        }
      },
      //运维数据
      DdXyYyYiDaData(){
        DdXyYyYiDaData().then(res => {
          _this.showLoading = false
          _this.tableData = res.data.body.data
        }).catch((err) => {
          _this.showLoading = false
          console.log(err)
        })
      },
      //库房数据
      //小学
      DdXyYyStDaData(){
        DdXyYyStDaData().then(res => {
          _this.showLoading = false
          _this.tableData = res.data.body.data
        }).catch((err) => {
          _this.showLoading = false
          console.log(err)
        })
      },
      //幼儿园
      DdXyYyYeyDaData(resData){
        DdXyYyYeyDaData().then(res => {
          _this.showLoading = false
          _this.tableData = res.data.body.data
        }).catch((err) => {
          _this.showLoading = false
          console.log(err)
        })
      },
      //安防数据
      DdXyYyAfDaData(){
        DdXyYyAfDaData().then(res => {
          _this.showLoading = false
          res.data.body.data.forEach(item=>{
            if(item.formData.checkboxField_ku7s0n2s){
              item.formData.checkboxField_ku7s0n2sArr =  item.formData.checkboxField_ku7s0n2s.join()
            }
          })
          _this.tableData = res.data.body.data
        }).catch((err) => {
          _this.showLoading = false
          console.log(err)
        })
      },
      getUserInfo() {
        userInfo()
          .then((res) => {
            let user = res.data.data
            if (user.userAccount === '19923016305' && user.realName === '尹元') {
              _this.showTable = true
              _this.showLoading = true
              _this.DdXyYyAfDaData()
            }
          }).catch((err) => {
          return _this.$message.error(err.message)
        })
      }
    },
    components: {
      ElTabPane,
      elTree
    }
  }
</script>

<style scoped lang="scss">
  .addrss{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

</style>
